<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class distribusi extends CI_Controller {

    public function __construct() {
        parent::__construct();

        $this->load->library('auth');
        $this->load->library('base');
        $this->load->library('ajaxresponse');
        $this->load->model("crud/m_distribusi_shu");
    }

    function index(){
        $this->auth->is_logged_in('form/login');
        $this->base->head_html('Distribusi SHU');
        $this->load->view('pengurus/br-05/distribusi');
    }

    function shu()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        
            $this->response->data = $this->m_distribusi_shu->insert();
            $this->response->status = "OK";
        echo json_encode($this->response);
    }

    function prepare_shu($year)
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $result = $this->m_distribusi_shu->get("YEAR(BULAN_DISTRIBUSI) = ".$year);
        if($result->num_rows() > 0)
        {
            $this->response->data = $result->result();
            $this->response->status = "EXIST";
        }
        else
        {
            $this->response->status = "OK";
        }
        echo json_encode($this->response);
    }

    function update()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $year = date("Y", strtotime($this->input->post("BULAN_DISTRIBUSI")));
        $result = $this->m_distribusi_shu->get("YEAR(BULAN_DISTRIBUSI) = ".$year);
        $this->response->data = $this->m_distribusi_shu->update();
        echo json_encode($this->response);
    }

    function at_year()
    {
        $this->auth->is_logged_in('form/login');
        $this->response = new ajaxresponse();
        $this->response->data = $this->m_distribusi_shu->insert();
        echo json_encode($this->response);
    }

}

?>
